package com.example.mysaat.service_menu_manual_test.allActivities;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Vibrator;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.SeekBar;
import android.widget.Switch;

import com.example.mysaat.R;
import com.example.mysaat.service_menu_manual_test.Listeners.MyFailOnclickListener;
import com.example.mysaat.service_menu_manual_test.Listeners.MyPassOnclickListener;
import com.example.mysaat.service_menu_manual_test.Listeners.MySeekBarChangeListener;

public class VibratorActivity extends AppCompatActivity {
    private SeekBar seekBar = null;
    private Button pass_btn = null;
    private Button fail_btn = null;
    private Switch aSwitch = null;
    private Vibrator vibrator = null;
    private final long VIBRATOR_IN_TIME_PAUSE = 500;
    private final long VIBRATOR_ON_TIME = 2000;
    private final long VIBRATOR_OFF_TIME = 500;
    private final long VIBRATOR_TIME = 0;
    private long[] pattern_Contiguously = {
            VIBRATOR_TIME,VIBRATOR_ON_TIME
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vibrator);
        init();
        initContent();
        vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);

    }

    public void init(){
        seekBar = findViewById(R.id.vibration_exit_stev);
        pass_btn = findViewById(R.id.vibrator_pass_btn);
        fail_btn = findViewById(R.id.vibrator_fail_btn);
        aSwitch = findViewById(R.id.vibrator_switch_on_off);
    }

    public void initContent(){
        pass_btn.setOnClickListener(new MyPassOnclickListener(VibratorActivity.this,null));
        fail_btn.setOnClickListener(new MyFailOnclickListener(VibratorActivity.this,null));
        seekBar.setOnSeekBarChangeListener(new MySeekBarChangeListener(this));
        aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    vibrator.vibrate(pattern_Contiguously,0);
                }else{
                    vibrator.cancel();
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        vibrator.cancel();
    }

    @Override
    protected void onStop() {
        super.onStop();
        vibrator.cancel();
    }
}
